package cn.itcast.hotel.controller;

import cn.itcast.hotel.vo.PageResult;
import cn.itcast.hotel.dto.HotelSearchDto;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Xiao
 * @version 1.0
 * @description 酒店Controller
 * @date 2021/11/11
 */
@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private IHotelService hotelService;

    /**
     * 搜索酒店数据，分页展示
     *
     * @param searchDto key/page/size/sortBy
     * @return
     */
    @PostMapping("/list")
    public PageResult getListBySearch(@RequestBody HotelSearchDto searchDto) {
        return hotelService.getListBySearch(searchDto);
    }

    /**
     * 数据聚合
     * @param searchDto key/page/size/sortBy
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody HotelSearchDto searchDto){
        return hotelService.getFilters(searchDto);
    }

    /**
     * 搜索框自动补全
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) {
        return hotelService.getSuggestions(prefix);
    }
}
